package com.job.Job;

import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;



public class AdminPage extends TDDBasePage{

	public AdminPage(BasePage basePage) {
		
		inheritSession(basePage);
		waitForPageToLoad(getTimeout());
						
		validate();
	}
	
	/**
	 * Validate that we are on the Admin page
	 */
	public void validate() {

		//super.validate();
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
		
	}
	public void clickConnectionsButton()
	{
		click(linktextLocator("Connections"));
	}
	public void clickProjectsButton()
	{
		click(linktextLocator("Projects"));
	}
	public void clickSystemRule()
	{
		click(linktextLocator("System Rules"));
	}
	public Object[] verifyAgent(String agent)
	{
		/* 2.5
		 * click(linktextLocator("Agents"));
		String text=getText(cssLocator("h3.label-2.agent-name"));
		return text.equals(agent);*/
		  Object[] array=new Object[2];
		  boolean exists = false;
		  List<String> runningAgents = new ArrayList<String>();
		  try{
		  assertEquals(true,driver.findElement(By.linkText("Agents")).isDisplayed());
		  //assertTrue("Agent link not found", (driver.findElement(By.linkText("Aget")).isDisplayed())!=false);
			  //String a="a";
			  //Assert.assertTrue(a.equals("a"),"Agent not found");
			  click(linktextLocator("Agents"));
		  int rowCount=driver.findElements(By.xpath("//body/div[1]/div/div/div[5]/div[5]/div[5]/table/tbody/tr")).size();
		
		  for(int i=1;i<=rowCount;i++){
		   runningAgents.add(driver.findElement(xpathLocator("//body/div[1]/div/div/div[5]/div[5]/div[5]/table/tbody/tr["+i+"]/td[2]/h3")).getText());
		  }
		  if(runningAgents.contains(agent)){
		   exists = true;
		  }
		 }
		  catch(Exception e)
		  {
			  log.debug(e.getMessage());
		  }
		  array[0]=exists;
		  array[1]=runningAgents;
		  return array;
	}
	public void clickAlgorithms()
	{
		click(linktextLocator("Algorithms"));
	}
	public void clickAddAlgorithm()
	{
		click(xpathLocator("//div[@id='admin-container']/div/h2/div/a/i/img"));
		click(linktextLocator("Add Algorithm"));
	}
	public void addAlgorithmRobot(String packName,final String autofile)
	{
		type(nameLocator("packagename"),packName);
		String winHandleBefore = driver.getWindowHandle();
		//waitForElementPreset(xpathLocator("//input[@name='files[0]']"),5000);
		//click(xpathLocator("//input[@name='files[0]']"));
		Thread thread = new Thread() {
		    public void run() {
		    	StringSelection stringSelection = new StringSelection(autofile);
				   Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null);
				  try
				  {
					  Thread.sleep(5000);
					  Runtime run = Runtime.getRuntime();
					  System.out.println(autofile);
						Process pp=run.exec("F:\\StepTwo\\datadirector\\datadirector\\automation\\TDDAutomation\\TDD\\file.exe");
					
				   /*Robot robot = new Robot();
				   robot.keyPress(KeyEvent.VK_CONTROL);
				   robot.keyPress(KeyEvent.VK_V);
				   robot.keyRelease(KeyEvent.VK_V);
				   robot.keyRelease(KeyEvent.VK_CONTROL);
				   robot.keyPress(KeyEvent.VK_ENTER);
				   robot.keyRelease(KeyEvent.VK_ENTER);*/
				  }
				  catch(Exception e)
				  {
					  e.printStackTrace();
				  }
		    }
		    	
		    };
		
		    thread.start();
		    //waitForElementPreset(xpathLocator("//body/div/div/div[5]/div[2]/div[5]/div[3]/div[2]/form/div[2]/div/input"),5000);
			//click(xpathLocator("//body/div/div/div[5]/div[2]/div[5]/div[3]/div[2]/form/div[2]/div/input"));  
			
			WebElement element = driver.findElement(xpathLocator("//body/div/div/div[5]/div[2]/div[5]/div[3]/div[2]/form/div[2]/div/span"));
			JavascriptExecutor executor = (JavascriptExecutor)driver;
			executor.executeScript("arguments[0].click();", element);
			
			//JavascriptExecutor  js=(JavascriptExecutor)driver;
		//js.executeScript("$('input[name=\"files[0]\"]').click();"); 
		/*try {
			Thread.sleep(5000);
		} catch (InterruptedException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}*/
		System.out.println(autofile);
		
		
		       //driver.switchTo().window(winHandleBefore);
				click(xpathLocator("//button[@type='submit']"));
		/* try
		  {
			  Thread.sleep(5000);
		   Robot robot = new Robot();
		  // robot.keyPress(KeyEvent.VK_CONTROL);
		  // robot.keyPress(KeyEvent.VK_V);
		   //robot.keyRelease(KeyEvent.VK_V);
		  // robot.keyRelease(KeyEvent.VK_CONTROL);
		   robot.keyPress(KeyEvent.VK_ENTER);
		   robot.keyRelease(KeyEvent.VK_ENTER);
		  }
		  catch(Exception e)
		  {
			  e.printStackTrace();
		  }*/
		 				try {
					Thread.sleep(20000);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				waitForElementPresent(idLocator("save_generator"),50000);
				click(idLocator("save_generator"));

	}
	
	public void addAlgorithm(String packName,String autofile)
	{
		type(nameLocator("packagename"),packName);
		waitForElementPresent(xpathLocator("//form[@name='addGeneratorForm']/div[2]/div/span"),5000);
		click(xpathLocator("//form[@name='addGeneratorForm']/div[2]/div/span"));
		//JavascriptExecutor  js=(JavascriptExecutor)driver;
		//js.executeScript("$('input[name=\"files[0]\"]').click();"); 
		Runtime run = Runtime.getRuntime();
        try {
        	//Thread.sleep(2000);
        	System.out.println(autofile);
			Process pp=run.exec("F:\\StepTwo\\datadirector\\datadirector\\automation\\TDDAutomation\\TDD\\file.exe");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}   
       try {
		Thread.sleep(20000);
	} catch (InterruptedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
       //driver.switchTo().window(winHandleBefore);
		click(xpathLocator("//button[@type='submit']"));
		try {
			Thread.sleep(5000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		waitForElementPresent(idLocator("save_generator"),5000);
		click(idLocator("save_generator"));
	}
	public void deleteAlgorithm()
	{
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
		for(int i=9;i<=15;i++)
		{
			
			JavascriptExecutor  js=(JavascriptExecutor)driver;
			js.executeScript("$('tr td button').show();");
			waitForElementPresent(xpathLocator("//tbody[@id='generators_list']/tr[9]/td[5]/button"),5000);
			click(xpathLocator("//tbody[@id='generators_list']/tr[9]/td[5]/button"));
			clickAlgorithms();
			if(isElementPresent(xpathLocator("//tbody[@id='generators_list']/tr[9]")))
			waitForElementPresent(xpathLocator("//tbody[@id='generators_list']/tr[9]"),5000);
		}
	}
	public void createNewRule()
	{
		click(cssLocator("img.arrow-down-b-img"));
		click(linktextLocator("New Rule"));
	}
	public void selectfromDropdown(String selectoption,String locator)
	{
		WebElement ul = driver.findElement(xpathLocator(locator));		
		List<WebElement> options = ul.findElements(By.tagName("li"));
		for (WebElement option : options) {			
	        if (selectoption.equals(option.getText())) {	        	
	            //System.out.println(option.getText());
	        	option.click();
	            break;
	        }
	    }
	}
	public void enterRuleDetails(String ruleName,String desc,String platform )
	{
		type(idLocator("rule_name"),ruleName);
		type(idLocator("rule_desc"),desc);
		System.out.println(platform);
		click(xpathLocator("//table/tbody/tr[2]/td[2]/div/a"));
		selectfromDropdown(platform,"//table/tbody/tr[2]/td[2]/div/div/ul");	
	}
	public boolean verifyRule(String par1,String par2,String par3,String par4,String par5)
	{
		boolean par1val=true;
		boolean par2val=true;
		boolean par3val=true;
		boolean par4val=true;	
		if(par5.equals("NEXTSTEP"))
		{
		par1val=verifySelectDripdown(par1,"//table[2]/tbody/tr/td/div/div/div/a/span");
		par2val=verifySelectDripdown(par2,"//table[2]/tbody/tr/td[2]/div/div/div/a/span");		
		if(isElementPresent(xpathLocator("//table[2]/tbody/tr/td[3]/div/input")))
		{
			par3val=verifySelectDripdown(par3,"//table[2]/tbody/tr/td[3]/div/input");			
		}
		else
		{
			par3val=verifySelectDripdown(par3,"//table[2]/tbody/tr/td[3]/div/div/div/a/span");
		}
		par4val= verifySelectDripdown(par2,"//table[2]/tbody/tr/td[4]/div/div/div/a/span");
		click(idLocator("rule-goto-next"));
		}
		return par1val&par2val&par3val&par4val;
	}
	public void defineRule(String par1,String par2,String par3,String par4,String par5)
	{
		click(xpathLocator("//table[2]/tbody/tr/td/div/div/div/a"));
		type(xpathLocator("//table[2]/tbody/tr/td/div/div/div/div/div/input"),par1);			
		selectfromDropdown(par1,"//table[2]/tbody/tr/td/div/div/div/div/ul");
		
		click(xpathLocator("//table[2]/tbody/tr/td[2]/div/div/div/a"));
		type(xpathLocator("//table[2]/tbody/tr/td[2]/div/div/div/div/div/input"),par2);			
		selectfromDropdown(par2,"//table[2]/tbody/tr/td[2]/div/div/div/div/ul");
		if(par3!=null)
		{
		if(isElementPresent(xpathLocator("//table[2]/tbody/tr/td[3]/div/div/a")))
		{
		click(xpathLocator("//table[2]/tbody/tr/td[3]/div/div/a"));
		type(xpathLocator("//table[2]/tbody/tr/td[3]/div/div/div/div/input"),par3);			
		selectfromDropdown(par3,"//table[2]/tbody/tr/td[3]/div/div/div/ul");
		}
		else
		{
			type(xpathLocator("//table[2]/tbody/tr/td[3]/div/input"),par3);
		}
		}
		if(par4!=null)
		{
		System.out.println(par4);
			click(xpathLocator("//table[2]/tbody/tr/td[4]/div/div/div/a"));
		type(xpathLocator("//table[2]/tbody/tr/td[4]/div/div/div/div/div/input"),par4);			
		selectfromDropdown(par4,"//table[2]/tbody/tr/td[4]/div/div/div/div/ul");
		}		
		if(par5.equals("ADD"))
		{			
			click(idLocator("rule-add"));
		}
		if(par5.equals("NEXTSTEP"))
		{
			click(idLocator("rule-goto-next"));
		}
	}
	public Boolean verifySourceSpecifications(int col,String connection,String owner,String table,String column)
	{		
		clickSource();
		Boolean connval=verifySelectDripdown(connection,"//*[@id='rule_column_connection_chzn']/a/span");
		Boolean ownerval=verifySelectDripdown(owner,"//*[@id='rule_column_owner_chzn']/a/span");
		Boolean tableval=verifySelectDripdown(table,"//*[@id='rule_column_table_chzn']/a/span");
		Boolean colval=verifySelectDripdown(column,"//*[@id='rule_column_column_chzn']/a/span");
		return connval&&ownerval&&tableval&&colval;
	}
	public void setSourceSpecifications(int col,String connection,String owner,String table,String column,String scope)
	{
		click(linktextLocator("Source"));				
		click(xpathLocator("//*[@id='rule_column_generate_types_chzn']/a"));
		selectfromDropdown("Source","//*[@id='rule_column_generate_types_chzn']/div/ul");	
		click(xpathLocator("//*[@id='rule_column_connection_chzn']/a"));
		waitForElementPresent(xpathLocator("//*[@id='rule_column_connection_chzn']/div/ul"),1000);
		type(xpathLocator("//*[@id='rule_column_connection_chzn']/div/div/input"),connection);	
		/*try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		selectfromDropdown(connection,"//*[@id='rule_column_connection_chzn']/div/ul");
		click(xpathLocator("//*[@id='rule_column_owner_chzn']/a"));
		type(xpathLocator("//*[@id='rule_column_owner_chzn']/div/div/input"),owner);
		waitForElementPresent(xpathLocator("//*[@id='rule_column_owner_chzn']/div/ul"),1000);
		selectfromDropdown(owner,"//*[@id='rule_column_owner_chzn']/div/ul");
		/*try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		waitForElementPresent(xpathLocator("//*[@id='rule_column_table_chzn']/a"),1000);
		click(xpathLocator("//*[@id='rule_column_table_chzn']/a"));
		waitForElementPresent(xpathLocator("//*[@id='rule_column_table_chzn']/div/ul"),1000);
		type(xpathLocator("//*[@id='rule_column_table_chzn']/div/div/input"),table);	
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		selectfromDropdown(table,"//*[@id='rule_column_table_chzn']/div/ul");
		/*try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		waitForElementPresent(xpathLocator("//*[@id='rule_column_column_chzn']/a"),1000);
		click(xpathLocator("//*[@id='rule_column_column_chzn']/a"));
		waitForElementPresent(xpathLocator("//*[@id='rule_column_column_chzn']/div/ul"),1000);		
		type(xpathLocator("//*[@id='rule_column_column_chzn']/div/div/input"),column);	
		/*try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		selectfromDropdown(column,"//*[@id='rule_column_column_chzn']/div/ul");
		if(scope==null)
		click(idLocator("save_rule"));		
		
	}
	public Boolean verifyDictionarySpecifications(int col,String connection,String owner,String table,String column)
	{			
		clickSource();
		Boolean connval=verifySelectDripdown(connection,"//*[@id='rule_columndic_connection_chzn']/a/span");
		Boolean ownerval=verifySelectDripdown(owner,"//*[@id='rule_columndic_owner_chzn']/a/span");
		Boolean tableval=verifySelectDripdown(table,"//*[@id='rule_columndic_table_chzn']/a/span");
		Boolean colval=verifySelectDripdown(column,"//*[@id='rule_columndic_column_chzn']/a/span");
		return connval&&ownerval&&tableval&&colval;
	}
	public void clickSource()
	{
		click(linktextLocator("Source"));
	}
	public Boolean verifySelectDripdown(String selectoption,String locator)
	{		
		String text=getText(xpathLocator(locator));
		System.out.println(getText(xpathLocator(locator)));
		System.out.println(selectoption);
		System.out.println(text.equals(selectoption));
		return text.equals(selectoption);
	}
	public void setAlgorithmSpecifications(int col,String algorithmTypes,String scope)
	{
		
		clickSource();
		click(xpathLocator("//*[@id='rule_column_generate_types_chzn']/a"));
		selectfromDropdown("Algorithm","//*[@id='rule_column_generate_types_chzn']/div/ul");	
		click(xpathLocator("//*[@id='rule_column_algorithm_chzn']/a"));
		waitForElementPresent(xpathLocator("//*[@id='rule_column_algorithm_chzn']/div/ul"),1000);
		selectfromDropdown(algorithmTypes,"//*[@id='rule_column_algorithm_chzn']/div/ul");
		//click(idLocator("addtspec_column"));
		if(scope==null)
			click(idLocator("save_rule"));	
		
	}
	public void setDictionarySpecifications(int col,String connection,String owner,String table,String column,String scope)
	{
		clickSource();
		click(xpathLocator("//*[@id='rule_column_generate_types_chzn']/a"));
		selectfromDropdown("Dictionary","//*[@id='rule_column_generate_types_chzn']/div/ul");	
		click(xpathLocator("//*[@id='rule_columndic_connection_chzn']/a"));
		waitForElementPresent(xpathLocator("//*[@id='rule_columndic_connection_chzn']/div/ul"),1000);
		type(xpathLocator("//*[@id='rule_columndic_connection_chzn']/div/div/input"),connection);		
		/*	try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		selectfromDropdown(connection,"//*[@id='rule_columndic_connection_chzn']/div/ul");
		click(xpathLocator("//*[@id='rule_columndic_owner_chzn']/a"));
		type(xpathLocator("//*[@id='rule_columndic_owner_chzn']/div/div/input"),owner);
		waitForElementPresent(xpathLocator("//*[@id='rule_columndic_owner_chzn']/div/ul"),1000);
		selectfromDropdown(owner,"//*[@id='rule_columndic_owner_chzn']/div/ul");
		/*try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		waitForElementPresent(xpathLocator("//*[@id='rule_columndic_table_chzn']/a"),1000);
		click(xpathLocator("//*[@id='rule_columndic_table_chzn']/a"));
		waitForElementPresent(xpathLocator("//*[@id='rule_columndic_table_chzn']/div/ul"),1000);
		type(xpathLocator("//*[@id='rule_columndic_table_chzn']/div/div/input"),table);		
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		selectfromDropdown(table,"//*[@id='rule_columndic_table_chzn']/div/ul");
		/*try {
			Thread.sleep(5000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		waitForElementPresent(xpathLocator("//*[@id='rule_columndic_column_chzn']/a"),1000);		
		click(xpathLocator("//*[@id='rule_columndic_column_chzn']/a"));
		waitForElementPresent(xpathLocator("//*[@id='rule_columndic_column_chzn']/div/ul"),1000);
		type(xpathLocator("//*[@id='rule_columndic_column_chzn']/div/div/input"),column);	
		/*try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		selectfromDropdown(column,"//*[@id='rule_columndic_column_chzn']/div/ul");
		if(scope==null)
			click(idLocator("save_rule"));			
		
	}
	public Boolean verifyCalculationsSpecifications(int col,String expression,String owner,String table,String column)
	{		
		clickSource();
		Boolean connval=getText(xpathLocator("//*[@id='calculations']/h5[2]/textarea")).equals(expression);
		//Boolean ownerval=verifySelectDripdown(owner,"//*[@id='rule_column_calc_owner_chzn']/a/span");
		//Boolean tableval=verifySelectDripdown(table,"//*[@id='rule_column_calc_table_chzn']/a/span");
		//Boolean colval=verifySelectDripdown(column,"//*[@id='rule_column_calc_table_chzn']/a/span");
		return connval;
	}
	public void setCalculationsSpecifications(int col,String expression,String owner,String table,String column,String scope)
	{
		clickSource();
		click(xpathLocator("//*[@id='rule_column_generate_types_chzn']/a"));		
		selectfromDropdown("Calculations","//*[@id='rule_column_generate_types_chzn']/div/ul");
		type(xpathLocator("//*[@id='calculations']/h5[2]/textarea"),expression);
		click(xpathLocator("//*[@id='rule_column_calc_owner_chzn']/a"));
		type(xpathLocator("//div[@id='rule_column_calc_owner_chzn']/div/div/input"),owner);
		waitForElementPresent(xpathLocator("//*[@id='rule_column_calc_owner_chzn']/div/ul"),1000);
		selectfromDropdown(owner,"//*[@id='rule_column_calc_owner_chzn']/div/ul");
		/*try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		waitForElementPresent(xpathLocator("//*[@id='rule_column_calc_table_chzn']/a"),1000);
		click(xpathLocator("//*[@id='rule_column_calc_table_chzn']/a"));
		waitForElementPresent(xpathLocator("//*[@id='rule_column_calc_table_chzn']/div/ul"),1000);
		type(xpathLocator("//*[@id='rule_column_calc_table_chzn']/div/div/input"),table);		
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		selectfromDropdown(table,"//*[@id='rule_column_calc_table_chzn']/div/ul");
		/*try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		waitForElementPresent(xpathLocator("//*[@id='rule_column_calc_column_chzn']/a"),1000);
		click(xpathLocator("//*[@id='rule_column_calc_column_chzn']/a"));
		waitForElementPresent(xpathLocator("//*[@id='rule_column_calc_column_chzn']/div/ul"),1000);
		type(xpathLocator("//*[@id='rule_column_calc_column_chzn']/div/div/input"),column);	
		/*try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		selectfromDropdown(column,"//*[@id='rule_column_calc_column_chzn']/div/ul");
		if(scope==null)
			click(idLocator("save_rule"));			
		
	}
	public void clickAddruleTotal()
	{
		click(idLocator("addrule_total"));		
	}
	public Boolean verifyAlgorithmSpecifications(int col,String algorithmTypes)
	{		
		clickSource();
		//System.out.println(algorithmTypes[i]);
		Boolean val=verifySelectDripdown(algorithmTypes,"//*[@id='rule_column_algorithm_chzn']/a/span");
		return val;
	}
	public Boolean verifyRangeSpecifications(int col,String start,String end)
	{		
		clickScopeLink();
		Boolean val1=getTextFromTextbox(xpathLocator("//*[@id='rule_column_scope_from']")).equals(start);
		//System.out.println("Range="+getTextFromTextbox(xpathLocator("//*[@id='rule_column_scope_from']")));
		Boolean val2=getTextFromTextbox(xpathLocator("//*[@id='rule_column_scope_to']")).equals(end);
		return val1&&val2;
	}
	public void setRangeSpecifications(int col,String start,String end)
	{
		clickScopeLink();		
		click(xpathLocator("//*[@id='rule_column_scope_types_chzn']/a"));
		selectfromDropdown("Range","//*[@id='rule_column_scope_types_chzn']/div/ul");	
		//waitForElementPreset(xpathLocator("//*[@id='rule_column_scope_from']"),1000);
		if(isVisible(xpathLocator("//*[@id='rule_column_scope_from']")))
		{
		System.out.println(start+"Date"+end);		
		type(xpathLocator("//*[@id='rule_column_scope_from']"),start);
		type(xpathLocator("//*[@id='rule_column_scope_to']"),end);
		}
		if(isVisible(xpathLocator("//*[@id='rule_column_scope_from_date']")))
		{
		System.out.println(start+"Date"+end);
		//click(idLocator("rule_column_scope_from_date"));
		//waitForElementPreset(xpathLocator("//body/table[3]/tbody/tr/td/div/div[2]/table"),5000);
		//selectDate("//body/table[3]/tbody/tr/td/div/div[2]/table","13");
		type(xpathLocator("//*[@id='rule_column_scope_from_date']"),getDatefromString(start));
		type(xpathLocator("//*[@id='rule_column_scope_to_date']"),getDatefromString(end));
		}
		click(idLocator("save_rule"));	
		
	}
	public String getDatefromString(String date)
	{
		String str="";
		str = date.replaceAll("[|]", "/");
		return str;
	}
	public int getNumberFromString(String str)
	{
		Pattern intsOnly = Pattern.compile("\\d+");
		Matcher makeMatch = intsOnly.matcher(str);
		makeMatch.find();
		String inputInt = makeMatch.group();
		System.out.println(inputInt);
		int i=Integer.parseInt(inputInt);
		return i;
	}
	public void clickScopeLink()
	{
		click(linktextLocator("Scope"));
	}
	public Boolean verifyStartSpecifications(int col,String start)
	{		
		clickScopeLink();
		Boolean val1=getTextFromTextbox(xpathLocator("//*[@id='rule_column_scope_from']")).equals(start);
		//System.out.println("Start="+getTextFromTextbox(xpathLocator("//*[@id='rule_column_scope_from']")));
		return val1;
	}
	public void setStartspecifications(int col,String start)
	{
		clickScopeLink();
		click(xpathLocator("//*[@id='rule_column_scope_types_chzn']/a"));
		selectfromDropdown("Start","//*[@id='rule_column_scope_types_chzn']/div/ul");			
		type(xpathLocator("//*[@id='rule_column_scope_from']"),start);
		click(idLocator("save_rule"));		
	}
	public void setContainmentspecifications(int col,String str)
	{
		click(xpathLocator("//ul[@id='table-tabs']/li[2]/a"));	
		//waitforPageToLoad(5000);
		click(xpathLocator("//*[@id='specColumnsTab']/ul[2]/div["+col+"]/table"));
		click(linktextLocator("Containment"));
		click(xpathLocator("//*[@id='tspec_column_containment_column_chzn']/a"));
		type(xpathLocator("//*[@id='tspec_column_containment_column_chzn']/div/div/input"),str);	
		/*try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		selectfromDropdown(str,"//*[@id='tspec_column_containment_column_chzn']/div/ul");	
		click(idLocator("addtspec_column"));	
		
	}
	public Boolean verifyEndSpecifications(int col,String end)
	{		
		clickScopeLink();
		Boolean val1=getTextFromTextbox(xpathLocator("//*[@id='rule_column_scope_to']")).equals(end);		
		//System.out.println(getText(xpathLocator("//*[@id='rule_column_scope_to']")));
		return val1;
	}
	public void setEndSpecifications(int col,String end)
	{
		clickScopeLink();
		click(xpathLocator("//*[@id='rule_column_scope_types_chzn']/a"));
		selectfromDropdown("Start","//*[@id='rule_column_scope_types_chzn']/div/ul");	
		type(xpathLocator("//*[@id='rule_column_scope_to']"),end);		
		click(idLocator("save_rule"));	
		
	}
	public Boolean verifyEqualspecifications(int col,String str)
	{		
		clickScopeLink();
		Boolean val1=getTextFromTextbox(xpathLocator("//*[@id='rule_column_string_scope']")).equals(str);		
		//System.out.println(getText(xpathLocator("//*[@id='rule_column_string_scope']")));
		return val1;
	}
	public void setEqualspecifications(int col,String str)
	{
		clickScopeLink();
		click(xpathLocator("//*[@id='rule_column_scope_string_types_chzn']/a"));
		selectfromDropdown("Equals","//*[@id='rule_column_scope_string_types_chzn']/div/ul");	
		type(xpathLocator("//*[@id='rule_column_string_scope']"),str);		
		click(idLocator("save_rule"));	
		
	}
	public Boolean verifyContainspecifications(int col,String str)
	{		
		clickScopeLink();
		Boolean val1=getTextFromTextbox(xpathLocator("//*[@id='rule_column_string_scope']")).equals(str);		
		//System.out.println(getText(xpathLocator("//*[@id='rule_column_string_scope']")));
		return val1;
	}
	public void setContainspecifications(int col,String str)
	{
		clickScopeLink();
		click(xpathLocator("//*[@id='rule_column_scope_string_types_chzn']/a"));
		selectfromDropdown("Contains","//*[@id='rule_column_scope_string_types_chzn']/div/ul");	
		type(xpathLocator("//*[@id='rule_column_string_scope']"),str);		
		click(idLocator("save_rule"));	
		
	}
	public Boolean verifyContainmentspecifications(int col,String str)
	{		
		click(xpathLocator("//ul[@id='table-tabs']/li[2]/a"));		
		click(xpathLocator("//*[@id='specColumnsTab']/ul[2]/div["+col+"]/table"));
		click(linktextLocator("Containment"));
		Boolean val1=verifySelectDripdown(str,"//*[@id='rule_column_containment_column_chzn']/a/span");	
		//System.out.println(getText(xpathLocator("//*[@id='rule_column_containment_column_chzn']/a/span")));
		return val1;
	}
	public void editSystemRule(String name)
	{
		waitForElementPresent(xpathLocator("//*[@id='sysrules_list']"),4000);
		JavascriptExecutor  js=(JavascriptExecutor)driver;
		js.executeScript("$('tr[data-id=\""+name+"\"] td button').show();");
		click(xpathLocator("//tr[@data-id='"+name+"']/td[4]/button"));
		
		
		
	}
	public void deleteSystemRule(String name)
	{
		
		click(xpathLocator("//tr[@data-id='"+name+"']/td[4]/button[2]"));
	}
	
	public void logOut() throws Exception{
		click(By.xpath("//body/div[1]/header/div/a/i[2]/img"));
		Thread.sleep(1000);
		click(By.xpath("//body/div[1]/header/div/ul/li[2]/a"));
		Thread.sleep(2000);
	}
}
